#!/bin/bash

if [ $# -lt 2 ]
then
    echo "请输入您的推送证书（从apple上下载的push证书cer文件），以及您的私钥（您电脑安装cer后产生的私钥p12文件）"
else 
    cer=${1}
    p12=${2}
    
    if [ ${cer##*.} != "cer" ]
    then 
   	echo "请输入cer文件："
	read cer	 
    fi
    if [ ${p12##*.} != "p12" ]
    then
	echo "请输入p12文件："
	read p12
    fi
    if [ ${cer##*.} = "cer" -a ${p12##*.} = "p12" ]
    then   
    	openssl x509 -in ${1} -inform DER -out developer_identity.pem -outform PEM
    	openssl pkcs12 -nocerts -in ${2} -out mykey.pem
    	openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out iphone_dev.p12
	rm -rf developer_identity.pem
 	rm -rf mykey.pem
        echo "如果遇到问题，请反映给开发者，谢谢您的建议～～"
    fi
fi
